<template>
    <basic-container>
        <avue-crud :option="option" :data="data" ref="crud" v-model="form" :table-loading="loading"
                   :permission="permissionList"
                   :page="page" @refresh-change="refreshChange" @search-change="searchChange"
                   @search-reset="searchReset"
                   @current-change="currentChange" @size-change="sizeChange" @on-load="onLoad">
            <!-- 自定义添加搜索条件  按日期搜索  -->
            <template slot="search">
                <el-col :md="12" :xs="12" style="height: 52px;">
                    <el-form-item label="有效期">
                        <el-date-picker text="有效期" v-model="acTime" type="datetimerange" range-separator="至" size="mini"
                                        start-placeholder="活动开始日期" :default-time="['12:00:00', '22:00:00']"
                                        end-placeholder="活动结束日期" align="right"
                                        format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
            </template>
            <template slot-scope="scope" slot="acRebate">
                <div v-if="scope.row.acRebate">{{scope.row.acRebate}}折</div>
            </template>
            <template slot-scope="scope" slot="menu">
                <!-- scope.row.acStage == 1 && -->
                <el-button @click="showAct(scope.row)" size="mini" type="text">查看</el-button>
                <el-button v-if=" scope.row.acStage==1" @click="enterActivity(scope.row)" size="mini" type="text">参加活动
                </el-button>
                <el-button @click="applyList(scope.row.id)" size="mini" type="text">活动商品</el-button>
            </template>
        </avue-crud>
        <!-- 参与活动 -->
        <el-drawer :wrapperClosable="false" :visible.sync="drawerActivity" :with-header="false" size="70%">
            <div class="demo-drawer__header">
                <div class="drawerHeader">
                    <strong>参加活动</strong>
                </div>
            </div>
            <div class="demo-drawer__content">
                <avue-form ref="formGoods" v-model="objActivity" :option="optionActivity">
                    <template slot-scope="scope" slot="acContent">
                        <el-input disabled :value="objActivity.acContent || '无活动说明'"></el-input>
                    </template>
                    <template slot="goods">
                        <avue-crud ref="goodsCrud" :data="goodsList" :option="optionGoods" v-model="objGoods"
                                   :table-loading="goodsloading"
                                   :permission="permissionList" :page="goodsPage" @selection-change="selectionChange"
                                   @refresh-change="refreshGoodsChange"
                                   @search-change="searchGoodsChange" @search-reset="searchGoodsReset"
                                   @current-change="currentGoodsChange"
                                   @size-change="sizeGoodsChange">
                            <template slot="tip">
                                <span style="color: #999;"> &nbsp; &nbsp;  (禁选说明：已参加活动商品禁选)</span>
                            </template>
                            <template slot-scope="{row}" slot="goodsMainPhotoUrl">
                                <img :src="row.goodsMainPhotoUrl" style="width:50px;height:50px;"/>
                            </template>
                            <template slot="search">
                                <el-col :span="10"  style="height: 52px;">
                                    <el-form-item label="商品分类" label-width="100px"
                                                  style="display: inline-block;width: 80%;">
                                        <el-cascader v-model="goodsClassLabel" :options="chooseProductUserOption"
                                                     size="mini" @change="handleUserChange"></el-cascader>
                                    </el-form-item>
                                </el-col>
                            </template>
                        </avue-crud>
                    </template>
                    <template slot="goodsStock">
                        <avue-crud ref="goodsStockCrud" :data="goodsStockList"
                                   :option="objActivity.acType=='2' && objActivity.groupBuyType=='2' && storeType=='1'?goodsStock:goodsStockSelf"
                                   v-model="objGoodsStock">
                            <template slot-scope="{ row }" slot="groupPrice">
                                <el-input type="number" v-model="row.groupPrice" placeholder="请输入内容"></el-input>
                            </template>
                            <template slot-scope="{ row }" slot="stocks">
                                <el-input type="number" v-model="row.stocks" placeholder="请输入内容"></el-input>
                            </template>
                            <template slot-scope="{ row }" slot="maxCount">
                                <el-input type="number" v-model="row.maxCount" placeholder="请输入内容"></el-input>
                            </template>
                            <template slot-scope="{ row }" slot="maxTimes">
                                <el-input type="number" v-model="row.maxTimes" placeholder="请输入内容"></el-input>
                            </template>
                            <!--							当活动类型是 2（拼团），group_buy_type 为 2（团长分销），非自营店铺 1，才显示团长分销-->
                            <template slot-scope="{ row }" slot="leaderReward">
                                <el-input type="number" v-model="row.leaderReward" placeholder="请输入内容"></el-input>
                            </template>
                        </avue-crud>
                    </template>
                    <template slot="sessionId" v-if="drawerActivity">
                        <el-select v-model="objActivity.sessionId" placeholder="请选择秒杀场次">
                            <el-option v-for="item in spikeTimes" :key="item.id" :label="item.label"
                                       :value="item.id"></el-option>
                        </el-select>
                    </template>
                    <template slot="menuForm">
                        <el-button type="primary" @click="handleSubmit" :loading="load">提 交</el-button>
                        <el-button @click="handleEmpty">关闭</el-button>
                    </template>
                </avue-form>
            </div>
        </el-drawer>
        <!-- 查看活动商品 -->
        <el-drawer :visible.sync="drawerList" :with-header="false" size="70%" :show-close="true">
            <div class="demo-drawer__header">
                <div class="drawerHeader">
                    <strong>活动商品</strong>
                </div>
            </div>
            <div class="demo-drawer__content" style="padding: 30px;">
                <avue-crud :data="dataList" :option="optionList" v-model="objList" ref="actGoodsList"
                           :table-loading="actGoodsLoading"
                           :permission="permissionList" :page="actGoodsPage" @refresh-change="refreshActGoodsChange"
                           @search-change="searchActGoodsChange"
                           @search-reset="searchActGoodsReset" @current-change="currentActGoodsChange"
                           @size-change="sizeActGoodsChange">
                    <template slot-scope="scope" slot="menu">
                        <el-button @click="goodsDetail(scope.row.goodsId)" size="mini" type="text">详情</el-button>
                        <el-button v-if="scope.row.agStatus == -1" @click="delByRefused(scope.row.id)" size="mini"
                                   type="text">删除
                        </el-button>
                    </template>
                </avue-crud>
            </div>
        </el-drawer>
        <el-drawer title="商品详情" size="70%" :withHeader=false :visible.sync="dialogTableVisible" width="70%">
            <add-goods v-if="dialogTableVisible" :disadledSpec="disadledSpec" :goodsId="goodsId" :isPublish="isPublish"
                       :isCheck="isCheck"
                       :isRedact="isRedact"></add-goods>
        </el-drawer>
        <el-dialog
                width="60%"
                :visible.sync="auditDialogFormVisible"
                title="活动详情"
                @close="closeDialog"
                append-to-body
                :close-on-click-modal="false"
        >
            <avue-form ref="formAudit" v-model="objAudit" :option="optionAudit">
                <template slot-scope="scope" slot="acTitle">
                    <div class="auditColor" v-if="objAudit.acTitle">{{objAudit.acTitle}}</div>
                </template>
                <template slot-scope="scope" slot="acTime">
                    <div class="auditColor" v-if="objAudit.preheatTime&& objAudit.acType==3">{{objAudit.preheatTime}}
                    </div>
                    <div class="auditColor" v-if="objAudit.acBeginTime && objAudit.acType!=3">{{objAudit.acBeginTime}} 至
                        {{objAudit.acEndTime}}
                    </div>
                </template>
                <template slot-scope="scope" slot="isSuperposition">
                    <div class="auditColor">
                        <p v-if="objAudit.isSuperposition">是 </p>
                        <p v-else>否 </p>
                    </div>
                </template>
                <template slot-scope="scope" slot="acH5AccUrl">
                    <el-image
                            style="width: 100px; height: 100px"
                            fit="contain"
                            :src="objAudit.acH5AccUrl"
                            :preview-src-list="[objAudit.acH5AccUrl]">
                    </el-image>
                </template>
                <template slot-scope="scope" slot="acFullcuts">
                    <div>
                        <div class="auditColor" v-if="objAudit.acType==1">
                            <p>{{objAudit.acRebate/100}} </p>
                        </div>
                        <div class="auditColor" v-if="objAudit.acType==2">
                            <p v-if="objAudit.groupBuyType==2">团长分销 </p>
                            <p v-else>普通拼团 </p>
                        </div>
                        <div class="auditColor" v-if="objAudit.acSessions.length>0 &&objAudit.acType==3">
                            <p v-for="item of objAudit.acSessions" :key="item.id">{{item.beginTime}} -
                                {{item.endTime}}</p>
                        </div>
                        <div class="auditColor" v-if="objAudit.acFullcuts.length>0&&objAudit.acType==7">
                            <p v-if="objAudit.fullType=='1'" v-for="item of objAudit.acFullcuts" :key="item.id">满 ￥
                                {{item.fullPrice}} , 减{{item.cutPrice}}</p>
                            <p v-if="objAudit.fullType=='2'" v-for="item of objAudit.acFullcuts" :key="item.id">满
                                {{item.fullPrice}} 件 , 减{{item.cutPrice}}</p>
                        </div>
                        <div class="auditColor" v-if="objAudit.acFullcuts.length>0 &&objAudit.acType==8">
                            <p v-if="objAudit.fullType=='1'" v-for="item of objAudit.acFullcuts" :key="item.id">满 ￥
                                {{item.fullPrice}} , 送{{item.goodsName}}</p>
                            <p v-if="objAudit.fullType=='2'" v-for="item of objAudit.acFullcuts" :key="item.id">满
                                {{item.fullPrice}} 件 , 送{{item.goodsName}}</p>
                        </div>
                        <div class="auditColor" v-if="objAudit.acFullcuts.length>0 &&objAudit.acType==9">
                            <p v-if="objAudit.fullType=='1'" v-for="item of objAudit.acFullcuts" :key="item.id">满 ￥
                                {{item.fullPrice}} , 打 {{item.discountNum/10}} 折</p>
                            <p v-if="objAudit.fullType=='2'" v-for="item of objAudit.acFullcuts" :key="item.id">满
                                {{item.fullPrice}} 件 , 打 {{item.discountNum/10}} 折</p>
                        </div>
                    </div>

                </template>
                <template slot-scope="scope" slot="joinGroup">
                    <div class="auditColor">
                        <p v-if="objAudit.joinGroup==1">是 </p>
                        <p v-else>否 </p>
                    </div>
                </template>
                <template slot-scope="scope" slot="acContent">
                    <div class="auditColor" v-if="objAudit.acContent">{{objAudit.acContent}}</div>
                </template>
            </avue-form>
        </el-dialog>
    </basic-container>
</template>

<script>
    import selFile from '@/components/file/selFile'
    import {
        getActPlatformList,
        listActivity,
        joinActivity,
        getGoodsList,
        delByRefused,
        getStoreInfo, getClassTree
    } from '@/api/base/activity/seller/discountAct'
    import {
        showGoodsStock
    } from '@/api/base/activity/seller/spikeAct';
    import addGoods from '@/views/base/goods/seller/addGoods';
    import {
        mapGetters
    } from "vuex";
    import {
        dateFormat
    } from '@/util/date.js'

    var Dict = JSON.parse(localStorage.getItem("mall-dictionary")).content;
    Dict.ACTIVITY_TYPE_ENUM.splice(0, 1);
    Dict.ACTIVITY_TYPE_ENUM.splice(3, 1);
    var ACTIVITY_STAGE_ENUM = [{
        label: '报名中',
        value: 1
    }, {
        label: '活动中',
        value: 3
    }, {
        label: '活动结束',
        value: 4
    },]
    export default {
        data() {
            return {
                goodsClassLabel: '',
                chooseProductUserOption: [], // 分类的列表
                goodsClassId: '',
                auditDialogFormVisible: false,
                objAudit: {},
                optionAudit: {
                    labelWidth: 150,
                    submitBtn: false,
                    emptyBtn: false,
                    column: [{
                        label: "活动名称",
                        prop: "acTitle",
                        span: 24,
                        formslot: true,
                    },
                        {
                            label: "活动时间",
                            prop: "acTime",
                            span: 24,
                            formslot: true,
                        },
                        {
                            label: "活动内容",
                            prop: "acFullcuts",
                            span: 24,
                            formslot: true,
                        },
                        {
                            label: "是否允许叠加",
                            prop: "isSuperposition",
                            display: true,
                            span: 24,
                            formslot: true,
                        },
                        {
                            label: "是否凑团",
                            prop: "joinGroup",
                            display: true,
                            span: 24,
                            formslot: true,
                        },
                        {
                            label: "活动横幅",
                            prop: "acH5AccUrl",
                            span: 24,
                            formslot: true,
                        },
                        {
                            label: "活动描述",
                            prop: "acContent",
                            span: 24,
                            formslot: true,
                        },
                    ]
                },
                load: false,
                pickerOption: {
                    disabledDate(time) {
                        return time.getTime() + 3600 * 1000 * 24 * 1 < Date.now();
                    },
                    shortcuts: [{
                        text: '今天',
                        onClick(picker) {
                            picker.$emit('pick', new Date());
                        }
                    }, {
                        text: '明天',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() + 3600 * 1000 * 24);
                            picker.$emit('pick', date);
                        }
                    }, {
                        text: '一周后',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', date);
                        }
                    }]
                },
                form: {},
                pcLink: '',
                h5Link: '',
                objActivity: {}, //参与活动对象
                query: {
                    type: 2,
                    //acStage: 1,//修复bug11732时sql调整了这个参数,这儿默认展示所有的平台活动吧
                    acStatus: 1,
                },
                dialogTableVisible: false, //商品详情
                isPublish: false,
                isCheck: false,
                isRedact: false,
                disadledSpec: false,
                goodsId: "",
                dialogLink: false,
                drawerList: false,
                drawerActivity: false,
                dataList: [],
                //参加活动商品
                goodsList: [],
                storeType: 0,//0,自营 1，非自营
                imageType: 1,
                data: [],
                loading: true,
                goodsloading: true,
                actGoodsLoading: true,
                rolesTree: [],
                rolesKeys: [],
                acTime: '',
                box: false,
                page: {
                    pageSize: 10,
                    currentPage: 1,
                    total: 0
                },
                goodsPage: {
                    pageSize: 10,
                    currentPage: 1,
                    total: 0
                },
                actGoodsPage: {
                    pageSize: 10,
                    currentPage: 1,
                    total: 0
                },
                idList: [],
                goodsQuery: {},
                actGoodsQuery: {
                    acId: ''
                },
                objList: {},
                spikeTimes: [],
                optionActivity: {
                    emptyBtn: false,
                    submitBtn: false,
                    search: true,
                    column: [{
                        label: "活动名称",
                        prop: "acTitle",
                        span: 8,
                        row: true,
                        disabled:true,
                        placeholder:''
                    }, {
                        label: "活动说明",
                        prop: "acContent",
                        formslot: true,
                        row: true,
                        span: 8,
                        disabled: true
                    }, {
                        label: '参团人数',
                        prop: 'activityPerson',
                        tip: '参团人数最少为2',
                        display: false,
                        valueDefault: 2,
                        row: true,
                        span: 8,
                        placeholder:'',
                        rules: [{
                            required: true,
                            message: '请输入参团人数'
                        }],
                    },
                        {
                            label: '秒杀场次',
                            prop: 'sessionId',
                            type: 'select',
                            row: true,
                            formslot: true,
                            span: 16,
                            display: false,
                            rules: [{
                                required: true,
                                message: '请选择秒杀场次'
                            }]
                        },
                        {
                            prop: "goods",
                            span: 24,
                            labelWidth:5,
                            formslot: true,
                        },
                        {
                            prop: 'goodsStock',
                            span: 24,
                            labelWidth:5,
                            formslot: true,
                            display: false,
                        }
                    ]
                },
                goodsStockList: [],
                objGoodsStock: {},
                goodsStock: {
                    size: 'mini',
                    excelBtn: false,
                    addBtn: false,
                    delBtn: false,
                    editBtn: false,
                    columnBtn: false,
                    border: true,
                    header: false,
                    align: 'center',
                    rowKey: 'id',
                    menu: false,
                    column: [{
                        label: '商品名称',
                        prop: 'goodsName',
                        align: 'left',
                    },
                        {
                            label: '规格属性',
                            width: 150,
                            prop: 'skuName'
                        },
                        {
                            label: '库存数量',
                            prop: 'stocks',
                            width: 120,
                            slot: true
                        },
                        {
                            label: '商城售价',
                            prop: 'showPrice',
                            width: 120,
                        },
                        {
                            label: '活动价格',
                            prop: 'groupPrice',
                            width: 120,
                            slot: true
                        },
                        {
                            label: '每人限购次数',
                            prop: 'maxTimes',
                            width: 120,
                            slot: true
                        },
                        {
                            label: '每人限购数量',
                            prop: 'maxCount',
                            width: 120,
                            slot: true
                        },
                        {
                            label: '团长奖励金额',
                            prop: 'leaderReward',
                            width: 120,
                            slot: true
                        }
                    ]
                },
                goodsStockSelf: {
                    size: 'mini',
                    excelBtn: false,
                    addBtn: false,
                    delBtn: false,
                    editBtn: false,
                    columnBtn: false,
                    border: true,
                    header: false,
                    align: 'center',
                    rowKey: 'id',
                    menu: false,
                    column: [{
                        label: '商品名称',
                        prop: 'goodsName',
                        align: 'left',
                    },
                        {
                            label: '规格属性',
                            width: 150,
                            prop: 'skuName'
                        },
                        {
                            label: '库存数量',
                            prop: 'stocks',
                            width: 120,
                            slot: true
                        },
                        {
                            label: '商城售价',
                            prop: 'showPrice',
                            width: 120,
                        },
                        {
                            label: '活动价格',
                            prop: 'groupPrice',
                            width: 120,
                            slot: true
                        },
                        {
                            label: '每人限购次数',
                            prop: 'maxTimes',
                            width: 120,
                            slot: true
                        },
                        {
                            label: '每人限购数量',
                            prop: 'maxCount',
                            width: 120,
                            slot: true
                        }
                    ]
                },
                objGoods: {},
                //店铺商品列表
                optionGoods: {
                    header: false,
                    selection: true,
                    searchMenuSpan: 8,
                    selectable: (row) => {
                        if (row.activityStatus) {
                            return false;
                        } else {
                            return true;
                        }
                    },
                    menu: false,
                    search: true,
                    border: true,
                    align: 'center',
                    column: [{
                        label: "商品图片",
                        prop: "goodsMainPhotoUrl",
                        slot: true,
                        width: 150,
                    }, {
                        label: "商品名称",
                        prop: "goodsName",
                        align: 'left',
                        search: true,
                        searchSpan: 8,
                    }, {
                        // 	label: "指定分类",
                        // 	prop: "goodsClassId",
                        // 	hide: true,
                        // 	type: 'select',
                        //     dicUrl: '/base/goodsClass/listManage?classLevel=2',
                        //     dicMethod: 'post',
                        //     props: {
                        //         label: 'className',
                        //         value: 'id'
                        //     },
                        // 	search: true,
                        // 	searchSpan: 8,
                        // }, {
                        label: "总库存",
                        prop: "stock",
                        width: 100,
                        span: 24,
                    }, {
                        label: "商城售价",
                        prop: "showPrice",
                        width: 150,
                        span: 24,
                    }]
                },
                //参加活动的商品列表
                optionList: {
                    size: 'mini',
                    excelBtn: false,
                    addBtn: false,
                    delBtn: false,
                    editBtn: false,
                    columnBtn: false,
                    border: true,
                    "align": "center",
                    rowKey: 'id',
                    height: 'auto',
                    // calcHeight: 380,
                    menuWidth: 100,
                    column: [{
                        label: "商品名称",
                        prop: "goodsName",
                        align: 'left',
                    },
                        {
                            label: "状态",
                            prop: "agStatus",
                            type: 'select',
                            width: 100,
                            dicData: Dict.STORE_BRAND_STATUS,
                        },
                        {
                            label: "活动名称",
                            width: 200,
                            prop: "acTitle",
                        }, {
                            label: "开始时间",
                            width: 150,
                            prop: "agBeginTime",
                        }, {
                            label: "结束时间",
                            width: 150,
                            prop: "agEndTime",
                        },
                    ]
                },
                //所有活动
                option: {
                    size: 'mini',
                    excelBtn: false,
                    addBtn: false,
                    delBtn: false,
                    editBtn: false,
                    viewBtn: false,
                    border: true,
                    "align": "center",
                    search: true,
                    rowKey: 'id',
                    columnBtn: false,
                    searchMenuSpan: 6,
                    column: [{
                        label: "活动名称",
                        prop: "acTitle",
                        align: 'left',
                        fixed: true,
                        search: true,
                    },
                        {
                            label: "活动类型",
                            prop: "acType",
                            type: 'select',
                            search: true,
                            dicData: Dict.ACTIVITY_TYPE_ENUM,
                            width: 100,
                        },
                        {
                            label: "创建时间",
                            prop: "addTime",
                            width: 150,
                        }, {
                            label: "创建人",
                            prop: "createUserName",
                            width: 150,
                        },
                        {
                            label: "开始时间",
                            prop: "acBeginTime",
                            width: 200,
                        }, {
                            label: "结束时间",
                            prop: "acEndTime",
                            width: 200,
                        }, {
                            label: "是否开启",
                            prop: "acStatus",
                            width: 120,
                            dicData: Dict.ACTIVITY_STATE_ENUM,
                            type: 'select',
                        }, {
                            label: "活动状态",
                            prop: "acStage",
                            type: 'select',
                            width: 100,
                            dicData: ACTIVITY_STAGE_ENUM,
                            search: true,
                        },

                    ]
                },
            };
        },
        watch: {
            'objActivity.acType'() {
                if (this.objActivity.acType == 2) { //拼团活动
                    this.optionActivity.column[2].display = true
                    this.optionActivity.column[3].display = false
                    this.optionActivity.column[5].display = true
                } else if (this.objActivity.acType == 3) { //秒杀
                    this.optionActivity.column[2].display = false
                    this.optionActivity.column[3].display = true
                    this.optionActivity.column[5].display = true
                } else {
                    this.optionActivity.column[2].display = false
                    this.optionActivity.column[3].display = false
                    this.optionActivity.column[5].display = false
                }
            },

        },
        computed: {
            ...mapGetters(["permission", 'userInfo']),
            permissionList() {
                return {};
            },
        },
        components: {
            selFile,
            addGoods
        },
        created() {
            this.getThisStoreInfo();
            // 获取分类
            getClassTree().then((res) => {
                if (res.status == 200) {
                    if (res.data.code == 200) {
                        this.chooseProductUserOption = res.data.data;
                    } else {
                        this.$message.error(res.data.message);
                    }
                }
            });
        },
        methods: {
            handleUserChange(value) {
                let val = [...value]
                let idArr = val.pop()
                this.goodsClassLabel = value
                this.goodsClassId = idArr
            },
            //查看店铺活动
            showAct(row) {
                console.log(row)
                if (row.acType == 1) {//是否叠加 不显示 折扣
                    this.optionAudit.column[1].label = '活动时间'
                    this.optionAudit.column[3].display = false
                    this.optionAudit.column[4].display = false//是否凑团
                    this.optionAudit.column[2].label = '活动折扣'
                } else if (row.acType == 2) {//拼团
                    this.optionAudit.column[1].label = '活动时间'
                    this.optionAudit.column[2].label = '活动场次'
                    this.optionAudit.column[3].display = false
                    this.optionAudit.column[4].display = true
                } else if (row.acType == 3) {//秒杀
                    this.optionAudit.column[1].label = '活动预热时间'
                    this.optionAudit.column[2].label = '活动场次'
                    this.optionAudit.column[3].display = false
                    this.optionAudit.column[4].display = false
                } else if (row.acType == 8) {//满赠
                    this.optionAudit.column[1].label = '活动时间'
                    this.optionAudit.column[2].label = '活动内容'
                    this.optionAudit.column[4].display = false
                    if (row.fullType == 1) {//满金额
                        this.optionAudit.column[3].display = false
                    } else if (row.fullType == 2) {//满件
                        this.optionAudit.column[3].display = true
                    }
                } else if (row.acType == 7) {//满减
                    this.optionAudit.column[1].label = '活动时间'
                    this.optionAudit.column[2].label = '活动内容'
                    this.optionAudit.column[4].display = false
                    if (row.fullType == 1) {//满金额
                        this.optionAudit.column[3].display = false
                    } else if (row.fullType == 2) {//满件
                        this.optionAudit.column[3].display = true
                    }
                } else if (row.acType == 9) {//满折
                    this.optionAudit.column[1].label = '活动时间'
                    this.optionAudit.column[2].label = '活动内容'
                    this.optionAudit.column[4].display = false
                    if (row.fullType == 1) {//满金额
                        this.optionAudit.column[3].display = false
                    } else if (row.fullType == 2) {//满件
                        this.optionAudit.column[3].display = true
                    }
                }
                this.objAudit = row
                this.auditDialogFormVisible = true
            }
            ,
            closeDialog() {
                // this.$nextTick(()=>{
                // 	this.$refs["formAudit"].clearValidate();
                // 	this.$refs["formAudit"].resetForm();
                // });
                this.auditDialogFormVisible = false;
            }
            ,
            delByRefused(id) {
                let obj = {
                    id: id
                }
                delByRefused(obj).then(res => {
                    if (res.data.code == 200) {
                        this.drawerList = false;
                        this.$message({
                            type: 'success',
                            message: '操作成功！'
                        });
                        this.onLoad(this.page)
                    } else {
                        this.$message.error(res.data.message);
                    }
                });
            }
            ,
            // 查看商品详情
            goodsDetail(id) {
                //查看
                this.goodsId = id;
                this.isCheck = true;
                this.dialogTableVisible = true;
            }
            ,

            //活动商品列表
            applyList(id) {
                this.actGoodsQuery.acId = id
                this.onActGoodsLoad(this.actGoodsPage)
                this.drawerList = true
            }
            ,
            //打开参与活动弹框
            enterActivity(row) {
                console.log(row);
                this.goodsQuery = {
                    storeId: row.storeId,
                    goodsStatus: 0,
                    activityId: row.id
                };
                if (row.acType == 3) {
                    var acTime = [];
                    row.acSessions.forEach(function (item) {
                        var data = {
                            label: '开始时间  ' + item.beginTime + '--结束时间  ' + item.endTime,
                            id: item.id
                        };
                        acTime.push(data);
                    });
                    console.log(acTime);
                    this.spikeTimes = acTime;
                }
                this.onGoodsLoad(this.goodsPage)
                this.$nextTick(() => {
                    if (acTime) {
                        this.objActivity.sessionId = acTime[0].id
                    }
                    this.objActivity.actId = row.id
                    this.objActivity.acTitle = row.acTitle
                    this.objActivity.acContent = row.acContent
                    this.objActivity.acType = row.acType
                    this.objActivity.groupBuyType = row.groupBuyType
                    console.log("this.objActivity.acType" + this.objActivity.acType)
                    console.log("this.objActivity.groupBuyType" + this.objActivity.groupBuyType)
                    this.drawerActivity = true
                })

            }
            ,
            //参加活动时，选择商品的回调
            selectionChange(list) {
                this.idList = []
                console.log(this.objActivity.acType)
                if (this.objActivity.acType == 2 || this.objActivity.acType == 3) { //拼团活动
                    if (list.length > 0) {
                        list.forEach((item, index) => {
                            this.idList[index] = item.id;
                        });
                        showGoodsStock(this.idList).then(res => {
                            if (res.data.code == 200) {
                                this.goodsStockList = res.data.data;
                                this.goodsStockList.forEach(item => {
                                    item.skuPrice = item.groupPrice
                                })
                            } else {
                                this.$message.error(res.data.message);
                            }
                        });
                    } else {
                        this.idList = [];
                        this.goodsStockList = [];
                    }
                } else {
                    list.forEach((item, index) => {
                        this.idList[index] = item.id
                    })
                }

                console.log(this.idList)
            }
            ,
            //确认参与活动
            handleSubmit() {
                this.load = true
                var data = {}
                var rep = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,2})?$/;
                if (this.idList.length == 0) {
                    this.$message.error('至少选择一个商品参加活动');
                    this.load = false
                    return;
                }

                if (this.objActivity.acType == 2) { //拼团活动
                    if (!this.objActivity.activityPerson) {
                        this.$message.error('请输入参团人数');
                        this.load = false
                        return;
                    }
                    var re = /^[0-9]+[0-9]*[0-9]*$/;
                    if (!re.test(this.objActivity.activityPerson)) {
                        this.$message.error('参团人数必须为正整数')
                        this.load = false
                        return;
                    } else if (this.objActivity.activityPerson < 2) {
                        this.$message.error('参团人数最少为2')
                        this.load = false
                        return;
                    } else if (this.objActivity.activityPerson > 10) {
                        this.$message.error('参团人数最大为10')
                        this.load = false
                        return;
                    }
                    if (this.idList.length == 0) {
                        this.$message.error('至少选择一个商品参加活动');
                        this.load = false
                        return;
                    }
                    for (let item of this.goodsStockList) {
                        item.activityPerson = this.objActivity.activityPerson;
                        if (!this.testIsInteger(item.stocks)) {
                            this.$message.error('库存数量应为大于0的整数');
                            this.load = false
                            return;
                        } else if (Number(item.stocks) > 1000000) {
                            this.$message.error('库存数量不能大于1000000');
                            this.load = false
                            return;
                        }
                        //判断输入的价格是否是大于等于0的整数或者小数
                        if (!rep.test(item.groupPrice)) {
                            if (Number(item.groupPrice) > 1000000) {
                                this.$message.error('价格不能大于1000000');
                            } else {
                                this.$message.error('价格应为大于0的数（保留两位小数）');
                            }
                            this.load = false
                            return;
                        } else if (Number(item.groupPrice) > 1000000) {
                            this.$message.error('价格不能大于1000000');
                            this.load = false
                            return;
                        }
                        if (!this.testIsInteger(item.maxTimes)) {
                            this.$message.error('限购次数格应为大于0的整数');
                            this.load = false
                            return;
                        } else if (Number(item.maxTimes) > 1000000) {
                            this.$message.error('限购次数不能大于1000000');
                            this.load = false
                            return;
                        }
                        if (!this.testIsInteger(item.maxCount)) {
                            this.$message.error('限购数量应为大于0的整数');
                            this.load = false
                            return;
                        } else if (Number(item.maxCount) > 1000000) {
                            this.$message.error('限购数量不能大于1000000');
                            this.load = false
                            return;
                        }
                    }
                    data = {
                        actId: this.objActivity.actId,
                        activityPerson: this.objActivity.activityPerson,
                        goodsIds: this.idList,
                        acGoodsSkuList: encodeURI(JSON.stringify(this.goodsStockList)),
                    };
                } else if (this.objActivity.acType == 3) {//秒杀活动
                    if (this.objActivity.sessionId == '') {
                        this.$message.error('至少选择一个秒杀场次');
                        this.load = false
                        return;
                    } else if (this.idList.length == 0) {
                        this.$message.error('至少选择一个商品参加活动');
                        this.load = false
                        return;
                    }
                    // var rep=/[\.]/; // 是否包含小数点
                    for (let item of this.goodsStockList) {
                        item.sessionId = this.objActivity.sessionId;
                        if (!this.testIsInteger(item.stocks)) {
                            this.$message.error('库存数量应为大于0的整数');
                            this.load = false
                            return;
                        } else if (Number(item.stocks) > 1000000) {
                            this.$message.error('库存数量不能大于1000000');
                            this.load = false
                            return;
                        }
                        //判断输入的价格是否是大于等于0的整数或者小数
                        if (!rep.test(item.groupPrice)) {
                            if (Number(item.groupPrice) > 1000000) {
                                this.$message.error('价格不能大于1000000');
                            } else {
                                this.$message.error('价格应为大于0的数（保留两位小数）');
                            }
                            this.load = false
                            return;
                        } else if (Number(item.groupPrice) > 1000000) {
                            this.$message.error('价格不能大于1000000');
                            this.load = false
                            return;
                        }
                        if (!this.testIsInteger(item.maxCount)) {
                            this.$message.error('限购数量应为大于0的整数');
                            this.load = false
                            return;
                        } else if (Number(item.maxCount) > 1000000) {
                            this.$message.error('限购数量不能大于1000000');
                            this.load = false
                            return;
                        }
                        if (!this.testIsInteger(item.maxTimes)) {
                            this.$message.error('限购次数格应为大于0的整数');
                            this.load = false
                            return;
                        } else if (Number(item.maxTimes) > 1000000) {
                            this.$message.error('限购次数不能大于1000000');
                            this.load = false
                            return;
                        }
                    }
                    data = {
                        actId: this.objActivity.actId,
                        sessionId: this.objActivity.sessionId,
                        goodsIds: this.idList,
                        acGoodsSkuList: encodeURI(JSON.stringify(this.goodsStockList))
                    };
                } else {
                    data = {
                        actId: this.objActivity.actId,
                        goodsIds: this.idList,
                    }
                }
                joinActivity(data).then(res => {
                    if (res.data.code == 200) {
                        this.$message({
                            type: 'success',
                            message: '操作成功！'
                        });
                        this.handleEmpty()
                    } else {
                        this.$message.error(res.data.message);
                        //this.drawerActivity = false;
                        this.$refs.goodsCrud.toggleSelection();
                        this.goodsStockList = [];
                    }
                    this.load = false
                });

            }
            ,
            //校验是否是大于等于0的整数
            testIsInteger(val) {
                let flag = false;
                var re = /^[0-9]*[1-9][0-9]*$/; //是否是大于或者等于0的整数
                if (re.test(val)) {
                    flag = true;
                } else {
                    flag = false;
                }
                return flag;
            }
            ,
            //关闭参与活动
            handleEmpty() {
                this.drawerActivity = false
                this.$refs.goodsCrud.toggleSelection();
                this.$refs.goodsCrud.searchReset();
                this.goodsStockList = [];
                this.goodsQuery = {};
            }
            ,
            // 参加活动时 商品表格方法
            searchGoodsReset() {
                this.idList = []
                this.goodsClassId = ''
                this.goodsClassLabel = ''
                this.goodsQuery.goodsClassId = ''
                this.$refs.goodsCrud.toggleSelection();
                this.onGoodsLoad(this.goodsPage);
            }
            ,
            searchGoodsChange(params, done) {
                this.idList = []
                this.$refs.goodsCrud.toggleSelection();
                this.goodsPage.currentPage = 1;
                params.goodsStatus = 0
                let activityId = this.goodsQuery.activityId;
                params.activityId = activityId;
                this.goodsQuery = params;
                params.goodsClassId = this.goodsClassId
                this.onGoodsLoad(this.goodsPage, params, done);
            }
            ,
            currentGoodsChange(currentPage) {
                this.goodsPage.currentPage = currentPage;
                this.onGoodsLoad(this.goodsPage)
            }
            ,
            sizeGoodsChange(pageSize) {
                this.goodsPage.pageSize = pageSize;
                this.onGoodsLoad(this.goodsPage)
            }
            ,
            refreshGoodsChange() {
                this.idList = []
                this.currentGoodsChange(1)
                this.$refs.goodsCrud.toggleSelection();
                this.onGoodsLoad(this.goodsPage);
            }
            ,
            onGoodsLoad(goodsPage, params = {}, done) {
                this.goodsloading = true;
                params.goodsStatus = 0;
                getGoodsList(
                    goodsPage.currentPage,
                    goodsPage.pageSize,
                    Object.assign(params, this.goodsQuery)
                ).then(res => {
                    if (res.data.code == 200) {
                        if (done) {
                            done();
                        }
                        this.goodsloading = false;
                        const data = res.data;
                        this.goodsPage.total = data.count;
                        this.goodsList = data.data;
                    } else if (res.data.code == 500) {
                        this.$message.error(res.data.message);
                        this.drawerActivity = false
                        this.goodsStockList = [];
                        this.goodsQuery = {};
                    }
                });

            }
            ,
            //查询店铺类型：自营非自营
            getThisStoreInfo() {
                getStoreInfo().then(res => {
                    if (res.data.code == 200) {
                        const data = res.data;
                        this.storeType = data.data.storeType;
                        console.log("aaa" + this.storeType)
                    }
                })
            }
            ,

            // 查看参加活动的商品时的商品表格 清空搜索
            searchActGoodsReset() {
                this.actGoodsQuery = {};
                this.onActGoodsLoad(this.actGoodsPage);
            }
            ,
            searchActGoodsChange(params, done) {
                this.actGoodsQuery = params;
                this.onActGoodsLoad(this.actGoodsPage, params, done);
            }
            ,

            currentActGoodsChange(currentPage) {
                this.actGoodsPage.currentPage = currentPage;
                this.onActGoodsLoad(this.actGoodsPage)
            }
            ,
            sizeActGoodsChange(pageSize) {
                this.actGoodsPage.pageSize = pageSize;
                this.onActGoodsLoad(this.actGoodsPage)
            }
            ,
            refreshActGoodsChange() {
                this.currentActGoodsChange(1)
                this.onActGoodsLoad(this.actGoodsPage);
            }
            ,
            onActGoodsLoad(actGoodsPage, params = {}) {
                console.log(actGoodsPage)
                console.log(params)
                listActivity(actGoodsPage.currentPage, actGoodsPage.pageSize, Object.assign(params, this.actGoodsQuery)).then(res => {
                    if (res.data.code == 200) {
                        this.actGoodsLoading = false;
                        const data = res.data;
                        this.actGoodsPage.total = data.count;
                        for (let item of data.data) {
                            item.agBeginTime = dateFormat(new Date(item.agBeginTime))
                            item.agEndTime = dateFormat(new Date(item.agEndTime))
                        }
                        console.log(data)
                        this.dataList = data.data

                    } else {
                        this.$message.error(res.data.message)
                    }

                });
            }
            ,
            //清空搜索
            searchReset() {
                this.acTime = ''
                this.query = {
                    type: 2,
                    //acStage: 1,
                    acStatus: 1,
                };
                this.onLoad(this.page);
            }
            ,
            searchChange(params, done) {
                this.page.currentPage = 1
                params.acBeginTime = this.acTime[0]
                params.acEndTime = this.acTime[1]
                params.type = 2
                params.acStatus = 1
                console.log(params)
                this.query = params;
                this.onLoad(this.page, params, done);
            }
            ,

            currentChange(currentPage) {
                this.page.currentPage = currentPage;
                this.onLoad(this.page)
            }
            ,
            sizeChange(pageSize) {
                this.page.pageSize = pageSize;
                this.onLoad(this.page)
            }
            ,
            //刷新
            refreshChange() {
                this.onLoad(this.page);
            }
            ,
            onLoad(page, params = {}, done) {
                this.loading = true;
                getActPlatformList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
                    if (done) {
                        done();
                    }
                    this.loading = false;
                    const data = res.data;
                    this.page.total = data.count;
                    this.data = data.data;
                });
            }
        }
    }
    ;
</script>

<style scoped>
    .drawerHeader {
        font-size: 20px;
        padding: 30px 20px;
    }

    .upload {
        display: flex;
        justify-content: flex-start;
        align-items: center;
    }

    .tsmsg {
        width: 200px;
        font-size: 10px;
        color: #999;
        margin: 0px;
        padding-left: 10px;
    }

    .diaLink {
        font-size: 20px;
        padding: 10px;
    }

    .diaLink p {
        padding: 10px;
    }

    .auditColor {
        color: #010101;
    }
</style>
